<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/Home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <el-row :gutter="20">
        <!-- 搜索区域 -->
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="queryInfo.query"
            clearable
            @clear="getOrderlist"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getOrderlist"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 订单数据列表表格 -->
      <el-table :data="orderList" stripe border>
        <!-- 设置索引列 -->
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <!-- 时间 -->
        <el-table-column prop="create_time" label="下单时间" width="180px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作" width="130px">
          <template slot-scope="scope">
            <!-- 修改按钮 -->
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              class="green_btn"
              @click="showEditDialog()"
            ></el-button>
            <!-- 物流进度按钮 -->
            <el-button
              size="mini"
              type="danger"
              icon="el-icon-location-information"
              class="red_btn"
              @click="showProgressBox"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        background
      >
      </el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="addressDialogVisible"
      width="40%"
      @close="addressDialogClosed"
    >
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="addressForm.address1"
            :options="cityData"
            :props="{ expandTrigger: 'hover' }"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog title="物流进度" :visible.sync="progressVisible" width="40%">
      <span>这是一段信息</span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "./citydata.js";
export default {
  name: "order",
  data() {
    return {
      queryInfo: {
        // *搜索的关键字
        query: "",
        // *当前的页数
        pagenum: 1,
        // *当前每页显示的数据条数
        pagesize: 5,
      },
      // *订单数据列表
      orderList: [],
      // *订单数据列表数据总数
      total: 0,
      //   *地址对话框的显示
      addressDialogVisible: false,
      // *修改地址表单数据
      addressForm: {
        address1: "",
        address2: "",
      },
      //   *修改地址验证规则
      addressFormRules: {
        address1: [
          { required: true, message: "请选择省市区/县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      // *省市区县
      cityData,
      // *物流进度对话框的显示
      progressVisible: false,
    };
  },
  created() {
    this.getOrderlist();
  },
  methods: {
    async getOrderlist() {
      const res = await this.$http.get("orders", { params: this.queryInfo });
      if (res.data.meta.status != 200) {
        return this.$message.error("获取订单列表失败！");
      }
      this.orderList = res.data.data.goods;
      this.total = res.data.data.total;
      this.pagenum = res.data.data.pagenum;
    },
    // *一个页面有几条 n条/页 修改时的事件
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderlist();
    },
    // *当前在第几页的监听事件
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOrderlist();
    },
    // a 修改地址对话框的显示
    showEditDialog() {
      this.addressDialogVisible = true;
    },
    // *修改地址对话框关闭事件
    addressDialogClosed() {
      this.$refs.addressFormRef.resetFields();
    },
    // *物流进度对话框
    async showProgressBox() {
     
      this.progressVisible = true;
    },
  },
};
</script>

<style scoped lang="less">
.el-cascader {
  width: 100%;
}
</style>
